package com.b511.swpu.cementbackend.repository;

import com.b511.swpu.cementbackend.entity.SysRole;
import org.springframework.data.domain.*;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface SysRoleRepository extends JpaRepository<SysRole, String> {
    SysRole findByName(String name);

    @Query(value = "select * from Sys_Role where id=:id",nativeQuery = true)
    SysRole findRoleById(String id);

    @Query(value = "select name from Sys_Role",nativeQuery = true)
    List<String> findSysRole();

    @Query(value = "select name from Sys_Role where id=:id",nativeQuery = true)
    String findNameById(@Param("id") String id);

    @Query(value = "select id from Sys_Role where name=:name",nativeQuery = true)
    String findIdByName(@Param("name") String name);

    Page<SysRole> findAll(Pageable pageable);

    @Query(value = "select * from Sys_Role where name like :name",nativeQuery = true)
    Page<SysRole> queryAllRoleLikeName(@Param("name") String name,Pageable pageable);
}
